<%@page import="org.mspring.mlog.core.ServiceFactory"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="org.mspring.platform.utils.StringUtils"%>
<%!
    private static final String password = "admin";
    private static final boolean toolsEnabled = true; 

    
    private boolean validate(String input){
        if(StringUtils.isBlank(input)){
            return false;
        }
        return input.equals(this.password); 
    }
    
    private void checkConfig(JspWriter out, HttpServletRequest request, HttpServletResponse response){
        if(!toolsEnabled){
            try{
                response.sendRedirect("disabled.jsp");
		    }
	        catch(Exception e){}
        }
		//验证密码是否设置
		if(StringUtils.isBlank(password)){
		    printScript(out, "alert('请先设置后台密码！');");
		    try{
		        response.sendRedirect("pwdnull.jsp");
		    }
	        catch(Exception e){}
		}
    }
    
    private boolean checkLogin(JspWriter out, HttpServletRequest request, HttpServletResponse response){
        try{
	    	Object obj = request.getSession().getAttribute("is_tools_logined");
	    	if(obj == null){
	    	    return false;
	    	}
	    	if(obj.equals(password)){
	    	    return true;
	    	}
	    	return false;
	    }
        catch(Exception e){
            return false;
        }
    }
    
    private void setLogin(HttpServletRequest request, String pwd){
        request.getSession().setAttribute("is_tools_logined", pwd);
    }
    
    private void printScript(JspWriter out, String script){
        try{
            out.print("<script type=\"text/javascript\">" + script + "</script>");   
        }
        catch(Exception e){}
    }
    
    private void initTreeItems(Long role){
        ServiceFactory.getInstallService().initTreeItems(role);
    }
    
%>